import config from '@/config/index'

// 创建请求实例
const request = (options) => {
    return new Promise((resolve, reject) => {
        uni.request({
            ...options,
            url: `${config.baseUrl}${options.url}`,
            timeout: config.timeout,
            header: {
                ...config.header,
                ...options.header
            },
            success: (res) => {
                if (res.statusCode === 200) {
                    resolve(res.data)
                } else {
                    reject(res)
                }
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}

export default request 